package com.jiangruan.javaproject.service;

import com.alibaba.fastjson.JSONObject;
import com.jiangruan.javaproject.Constants;
import com.jiangruan.javaproject.bean.Constellations;
import com.jiangruan.javaproject.request.HttpUtils;

import java.net.URLEncoder;
import java.util.Scanner;

/**
 * @author:xulonghua
 * @email:3162193565@qq.com
 * @desc:聚合函数的星座查询
 * @datetime 2021/12/26 16:34
 */
public class Constellation {
public  Constellations  constellation(){
    Scanner scanner = new Scanner ( System.in );
    System.out.println ("请输入你的星座");
    String consName = scanner.next ();
    String encode = URLEncoder.encode ( consName );
    //json解析
    String Url= Constants.Constellation_URL+"?consName="+encode+"&type=today"+"&key="+Constants.Constellation_KEY;
    String result = HttpUtils.get ( Url );
    System.out.println (result);
    //json
    //把result数据解析成WeatherQuery类型的
    Constellations constellations = JSONObject.parseObject ( result, Constellations.class );
    return constellations;
}

    public static void main(String[] args) {
        Constellation constellation = new Constellation ();
        Constellations constellation1 = constellation.constellation ();
        System.out.println ("name :"+constellation1.getName ());
        System.out.println ("datetime :"+constellation1.getDatetime ());
        System.out.println ("date :"+constellation1.getDate ());
        System.out.println ("all :"+constellation1.getAll ());
        System.out.println ("color :"+constellation1.getColor ());
        System.out.println ("Health :"+constellation1.getHealth ());
        System.out.println ("love :"+constellation1.getLove ());
        System.out.println ("Money: "+constellation1.getMoney ());
        System.out.println ("Number ："+constellation1.getNumber ());
        System.out.println ("QFriend ："+constellation1.getQFriend ());
        System.out.println ("Summary ："+constellation1.getSummary ());
        System.out.println ("Work ："+constellation1.getWork ());
        System.out.println ("error ："+constellation1.getError_code ());

    }

}
